"""
多线程-继承Thread类

Version: 0.1
Author: yuwl
Date：2024-4-9
"""

from collections.abc import Callable
from random import randint
from threading import Thread
from time import time, sleep
from typing import Any, Iterable, Mapping


class DownloadTask(Thread):

    def __init__(self, filename):
        super().__init__()
        self._filename = filename

    def run(self):
        print('开始下载%s...' % self._filename)
        time_to_download = randint(5, 10)
        sleep(time_to_download)
        print('%s下载完成！耗费了%d秒' % (self._filename, time_to_download))

def main():
    strat = time()
    t1 = DownloadTask('Python入门')
    t1.start()
    t2 = DownloadTask('file.avi')
    t2.start()
    # 等待线程执行结束
    t1.join()
    t2.join()
    end = time()
    print('总共耗费了%.2f秒.' % (end - strat))


if __name__ == '__main__':
    main()